<!-- 充值审核 -->
<template>
  <div>
    <el-dialog :title="recharData.title" :visible.sync="recharData.showModal" width="650px" top="5vh">
      <el-form label-width="90px" :model="data" ref="update" :rules="rules" v-loading="showLoading" element-loading-text="数据加载中">
        <el-row>
          <el-col :offset="3" :span="18">
            <el-form-item label="状态" prop="status">
              <el-select v-model="data.status" placeholder="请选择状态">
                <el-option v-for="item in recharlist" :key="item.code" :label="item.name" :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :offset="3" :span="18">
            <el-form-item label="备注">
              <el-input type="textarea" :rows="3" v-model="data.remark" placeholder="请输入备注"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 底部按钮开始 -->
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" type="primary" @click="sub">提交</el-button>
        <el-button size="medium" @click="recharData.showModal = false">取消</el-button>
      </span>
      <!-- 底部按钮结束 -->
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: ['recharData'],
  data () {
    return {
      showLoading: false,//是否显示loading
      recharlist: [], // 状态列表
      title: '',//标题
      // 提交的数据
      data: {
        status: '',
        remark: '',
        id: '',
      },
      //表单校验
      rules: {
        status: [
          { required: true, message: '请选择状态', trigger: 'blur' },
        ]
      }
    }
  },
  methods: {
    //审核
    sub () {
      this.$refs['update'].validate(async (valid) => {
        if (valid) {
          this.showLoading = true
          let result = await this.request.httpRequest('PUT', '/recharge/approve', this.data)
          if (result.code == 200) {
            this.recharData.showModal = false
            this.$message({ type: 'success', message: result.msg })
            this.$emit('close')
          } else {
            this.$message({ type: 'error', message: result.msg })
          }
          this.showLoading = false
        }
      })
    },
    //获取详情
    async getDetail () {
      if (this.recharData.recharID) {
        let url = `/recharge/get/${this.recharData.recharID}`
        let result = await this.request.httpRequest('GET', url)
        if (result.code == 200) {
          this.data.id = result.data.id;
          this.data.status = result.data.status;
          this.data.remark = result.data.remark;
        } else {
          this.$message({ type: 'error', message: result.msg })
        }
      }
    },
    //获取字典表
    async getterm () {
      this.recharlist = await this.common.enumsList("RECHARGE_STATUS");
      this.data.status = '0';
    },
  },
  mounted () {
    this.getDetail();
    this.getterm();
  }
}
</script>
